﻿<?php 
header("content-type:text/html;charset=utf-8"); 
ini_set("magic_quotes_runtime",0); 
require 'class.phpmailer.php'; 
try 
{ 
	$mail = new PHPMailer(true); 
	$mail->IsSMTP(); 
	$mail->CharSet='UTF-8'; //设置邮件的字符编码，这很重要，不然中文乱码 
	$mail->SMTPAuth = true; //开启认证 
	$mail->Port = 25; 
	$mail->Host = "smtpdm.aliyun.com"; 
	$mail->Username = "lucky@aliyundm.hengrunkeji.com"; 
	$mail->Password = "2CWR9QN6eB"; 
	//$mail->IsSendmail(); //如果没有sendmail组件就注释掉，否则出现“Could not execute: /var/qmail/bin/sendmail ”的错误提示 
	$mail->AddReplyTo("key@hengrunkeji.com","mckee");//回复地址 
	$mail->From = "lucky@aliyundm.hengrunkeji.com"; 
	
	
	 
	
	$phone = $_POST['phone'];
	$tomail = $_POST['tomail'];
	//$titel = $_POST['titel'];
	$titel = '咨询反馈';
	//$contents = $_POST['contents'];	
	$contents = '已收到邮件，会尽快回复！';
	$pattern='/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/';
	$phonepattern = "/13[123569]{1}\d{8}|15[1235689]\d{8}|188\d{8}/";
	$kzcontents = '';
	if(!empty($tomail)){					
		if(!preg_match( $pattern, $tomail)){
			$info = array(
				'code' => -1,
				'message' => '请输入正确的邮件地址'
			);
			exit(json_encode($info,JSON_UNESCAPED_UNICODE));
		}
		/*
		if(empty($titel)){
			$info = array(
				'code' => -2,
				'message' => '请输入标题'
			);
			exit(json_encode($info,JSON_UNESCAPED_UNICODE));
		}		
		$mail->FromName = "恒润科技"; 	
		$mail->AddAddress($tomail); 
		$mail->Subject = $titel; 
		$mail->Body = $contents; 
		//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; //当邮件不支持html时备用显示，可以省略 
		$mail->WordWrap = 80; // 设置每行字符串的长度 
		//$mail->AddAttachment("f:/test.png"); //可以添加附件 
		$mail->IsHTML(true); 
		$mail->Send();
		*/
		
		$kzcontents = '邮箱地址：'.$tomail.'<br />';
		if(!empty($phone)){
			$kzcontents = $kzcontents.'电  话：'.$phone.'<br />';
		}
	}else{
		if(strlen($phone) == "11" && preg_match( $phonepattern, $phone)){
			$kzcontents = '电话：'.$phone.'<br />';
		}else{
			$info = array(
			'code' => -4,
			'message' => '请输入正确的手机号'
			);
			exit(json_encode($info,JSON_UNESCAPED_UNICODE)); 
		}
	}
	
	
	$mail->FromName = "恒润科技留言"; 
	$mail->AddAddress("key@hengrunkeji.com");
	$mail->Subject = "恒润科技留言"; 
	$mail->Body = $kzcontents; 
	$mail->WordWrap = 80;
	$mail->IsHTML(true); 
	$mail->Send();

	$mail->FromName = "恒润科技留言"; 	
	$mail->AddAddress("zhaoyang@hengrunkeji.com");
	$mail->Subject = "恒润科技留言"; 
	$mail->Body = $kzcontents; 
	$mail->WordWrap = 80;
	$mail->IsHTML(true); 
	$mail->Send();
	
	$info = array(
			'code' => 1,
			'message' => '发送成功'
		);
	exit(json_encode($info,JSON_UNESCAPED_UNICODE)); 
} catch (phpmailerException $e) { 
		$info = array(
			'code' => -3,
			'message' => '发送失败'
		);
		exit(json_encode($info,JSON_UNESCAPED_UNICODE)); 
	} 
?> 